package com.gjszn.kh.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.gjszn.kh.context.MemberRCodeContext;

/**    
* @Title: RegisterInterceptor.java  
* @Package com.gjszn.kh.interceptor    
* @author jys@nx-yt.com    
* @date 2015年12月31日 上午10:46:26  
* @version V1.0    
* @Description: TODO(用一句话描述该文件做什么)
********************************************/
public class RegisterInterceptor implements HandlerInterceptor{
	
	private static Logger log = LogManager.getRootLogger();
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		//String memeber = (String)request.getSession().getAttribute("member");
		String rcode = (String)request.getSession().getAttribute("rcode");
		boolean rcode_flag = (rcode == null) || "".equals(rcode) || (!MemberRCodeContext.isInclude(rcode));
		if(rcode_flag){
			log.info("跳转到输入推荐码界面");
			response.sendRedirect(request.getContextPath() + "/input/rcode");
			return false;
		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}

}

